package com.jacklin.market.coupon.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jacklin.market.coupon.domain.UserCoupon;
import com.jacklin.market.coupon.service.UserCouponService;
import org.jacklin.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @describe: UserCouponController
 * @author: jacklin
 * @date: 2022-03-28 22:43
 */
@RestController
@RequestMapping(value = "/userCoupon")
public class UserCouponController {


    @Autowired
    private UserCouponService userCouponService;

    /**
     * @describe: 根据券码查询用户优惠券信息
     * @author: jacklin
     * @date: 2022/3/28
     **/
    @GetMapping(value = "/getByCouponCode")
    public Result<?> getByCouponCode(@RequestParam String userId, @RequestParam String couponCode) {
        LambdaQueryWrapper<UserCoupon> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        UserCoupon userCoupon = userCouponService.getOne(lambdaQueryWrapper.eq(UserCoupon::getCouponCode, couponCode).eq(UserCoupon::getUserId, userId));
        return Result.OK(userCoupon);
    }

    /**
     * @describe: 更新用户优惠券使用状态
     * @author: jacklin
     * @date: 2022/3/28
     **/
    @PostMapping(value = "/updateUserCouponStatus")
    public Result<?> updateUserCouponStatus(@RequestBody UserCoupon userCoupon) {
        return Result.OK(userCouponService.updateUserCouponStatus(userCoupon.getUserId(), userCoupon.getCouponCode()));
    }
}
